#include "uhm/common.hxx"
#include "uhm/util.hxx"
#include "uhm/discrete/base/cache.hxx"

#define N 1

using namespace uhm;

typedef ID_Node_<N>             Id_Nd;
typedef Cache_<Id_Nd, Int_> Cache;

int main (int argc, char **argv) {

  Cache::_Id_Nd_ nd;
  Cache::_Uhm_ uhm = 10;

  Map_<Cache::_Id_Nd_> factor, schur;

  factor.push_begin(3);
  nd.set_id(0, 10); factor.push(nd);
  nd.set_id(0, 20); factor.push(nd); 
  nd.set_id(0, 40); factor.push(nd);
  factor.push_end();

  schur.push_begin(3);
  nd.set_id(0, 11); schur.push(nd);
  nd.set_id(0, 31); schur.push(nd); 
  nd.set_id(0, 21); schur.push(nd); 
  schur.push_end();

  std::cout << factor << "\n"
            << schur << "\n";

  Cache::Entry_ a(factor, schur, uhm);
  Cache::Entry_ b(factor, schur, uhm);

  schur.clear();
  schur.push_begin(3);
  nd.set_id(0, 21); schur.push(nd);
  nd.set_id(0, 41); schur.push(nd);
  nd.set_id(0, 11); schur.push(nd);
  schur.push_end();

  Cache::Entry_ c(factor, schur, uhm);

  std::cout << "- a - \n" << a ;
  std::cout << "- b - \n" << b ;
  std::cout << "- c - \n" << c ;
  
  std::cout << "a==b ? " << (a==b) << "\n";
  std::cout << "a==c ? " << (a==c) << "\n";

  Cache cache;
  Cache::Entry_ *out;
  Int_ flag;
  cache.push_begin();
  flag = cache.push(c, &out); std::cout << flag << *out << "\n"; hold();
  flag = cache.push(a, &out); std::cout << flag << *out << "\n"; hold();
  cache.push_end();
  
  std::cout << "- Pushing Test - \n" << cache << "\n";

  cache.push_begin();
  flag = cache.pull(c, &out);
  std::cout << "  pulling from cache " << flag << "\n";
  cache.push_end();
  
  std::cout << "- Pulling Test - \n" << cache << "\n";
  return true;
}


